#include "TcpServer.h"
#include "Eventloop.h"
#include "Acceptor.h"
#include "Tcpconnection.h"

namespace liu
{
	TcpServer::TcpServer(Eventloop* pLoop)
		:m_pLoop(pLoop),
		m_pAcceptor(make_unique<Acceptor>(pLoop))		
	{
		m_pAcceptor->m_newConnCabllback = bind(&TcpServer::newConnection,this, placeholders::_1);
	}

	TcpServer::~TcpServer()
	{
		
	}

	void TcpServer::start()
	{
		RUN_TRACE;
		m_pAcceptor->listen();
	}

	void TcpServer::newConnection(int sockfd)
	{
		RUN_TRACE;
		shared_ptr<TcpConnection> pConn{new TcpConnection(m_pLoop, sockfd)};
		pConn->m_connCallback = m_ConnectionCallback;
		pConn->connectEstablished();
		m_vecTcpconnections.push_back(pConn);
	}

}